package com.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.util.ConfigUtil;


import com.util.BODY;
import com.util.DateUtil;
import com.util.HttpRequest;
import com.util.JSONUtil;
import com.util.OpenKey;
import com.util.ReadConfig;
import com.util.SessionInfo;

//缴存基本情况
@Controller
@RequestMapping("/jcjbqkcontroller")
public class jcjbqkcontroller {

	private static final Logger logger = Logger.getLogger(jcjbqkcontroller.class);
	Map map  = new HashMap();
	List list = new ArrayList();
	 

	@RequestMapping("/test")
	@ResponseBody
	public String entryinterface(HttpServletRequest request, String sj,HttpServletResponse response,HttpSession session, String limit ,String id,String start,String end) throws IOException{
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		Map reqMap = new HashMap();
		BODY b=new BODY();
		b.setGRZH(sessionIn.getGRZH());
		reqMap.put("AUTHORITY", "YBGJJ107");
		reqMap.put("OpenKey", sessionIn.getKEY());
		reqMap.put("BODY",b);
		OpenKey opk=new OpenKey();
		String result=opk.getOpenKey(reqMap, session);
		logger.info("接口返回内容:"+result);
		if(result != null){
			Map resMap = JSONUtil.toMap(result);
			if(resMap.get("RETURNCODE").equals("100")){
				Map mx=JSONUtil.toMap(JSONUtil.ToJsongString2(resMap.get("body")));
				List retlist=(List) mx.get("RETDATA");
				/*for(int i=0;i<retlist.size();i++){
					Map map=(Map) retlist.get(i);
					map.put("SJHM",sessionIn.getSJHM());
				}*/
				map.put("code", 0);
				map.put("msg", "1");
				map.put("data", mx.get("RETDATA"));
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
			}else{
				map.put("code", 1);
				map.put("msg", "1");
				map.put("CW", resMap.get("RETURNDESC").toString());
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
			}
		}
	
		return null;
	}
	@RequestMapping("/dy")
	@ResponseBody
	public String dy(HttpServletRequest request, HttpServletResponse response,HttpSession session, String limit ,String id,String start,String end) throws IOException{
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		Map reqMap = new HashMap();
		BODY b=new BODY();
		b.setGRZH(sessionIn.getGRZH());
		reqMap.put("AUTHORITY", "YBGJJ146");
		reqMap.put("OpenKey", sessionIn.getKEY());
		reqMap.put("BODY",b);
		OpenKey opk=new OpenKey();
		String result=opk.getOpenKey(reqMap, session);
		logger.info("接口返回内容:"+result);
		if(result != null){
			Map resMap = JSONUtil.toMap(result);
			if(resMap.get("RETURNCODE").equals("100")){
				Map mx=JSONUtil.toMap(JSONUtil.ToJsongString2(resMap.get("body")));
				map.put("code", 0);
				map.put("msg", "1");
				map.put("data", mx);
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
			}else{
				map.put("code", 1);
				map.put("msg", "1");
				map.put("CW", resMap.get("RETURNDESC").toString());
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
			}
		}
	
		return null;
	}
	@RequestMapping("/test1")
	@ResponseBody
	public String entryinterface1(HttpServletRequest request, HttpServletResponse response,HttpSession session, String limit ,String id,String start,String end) throws IOException, ParseException{
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		Map reqMap = new HashMap();
		DateUtil NIAN=new DateUtil();
		
		Date qsny=new Date();
		String qsrq=qsny+"";
		String zzqr=NIAN.minusM(qsny);
		System.out.println(qsrq+zzqr);
		reqMap.put("AUTHORITY", "YBGJJ109");
		reqMap.put("OpenKey", sessionIn.getKEY());
		BODY body=new BODY();
		body.setGRZH(sessionIn.getGRZH());
		body.setQSRQ(zzqr);
		body.setZZRQ(qsrq);
		reqMap.put("BODY", body);
		OpenKey opk=new OpenKey();
		String  result = opk.getOpenKey(reqMap, session);    
		logger.info("YBGJJ109接口返回内容:"+result);
		if(result != null){
			Map resMap = JSONUtil.toMap(result);
			if(resMap.get("RETURNCODE").equals("100")){
				//List resList = JSONUtil.toList(resMap.get("body").toString());
				Map mx=JSONUtil.toMap(JSONUtil.ToJsongString2(resMap.get("body")));
				//map.put("count", resList.size());
				map.put("code", 0);
				map.put("msg", null);
				map.put("data", mx.get("RETDATA"));
				//list.add(resMap);
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
			}
		}
	
		return null;
	}
	@RequestMapping("/test2")
	@ResponseBody
	public String xgsjh(HttpServletRequest request, HttpServletResponse response,HttpSession session, String limit ,String id,String start,String sjhm) throws IOException{
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		Map reqMap = new HashMap();
		reqMap.put("AUTHORITY", "YBGJJ184");
		reqMap.put("OpenKey", sessionIn.getKEY());
		BODY body=new BODY();
		body.setGRZH(sessionIn.getGRZH());
		body.setSJHM(sjhm);
		body.setCZY("网厅");
		reqMap.put("BODY", body);
		OpenKey opk=new OpenKey();
		String  result = opk.getOpenKey(reqMap, session);    
		logger.info("YBGJJ109接口返回内容:"+result);
		if(result != null){
			Map resMap = JSONUtil.toMap(result);
			if(resMap.get("RETURNCODE").equals("100")){
				map.put("code", 0);
				map.put("msg", "1");
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
			}else{
				map.put("code", 1);
				map.put("msg", "1");
				map.put("CW", resMap.get("RETURNDESC").toString());
				list.add(resMap);
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
			}
		}
	
		return null;
	}
	/**
	 * 提取判断条件是：男年龄不能小于60 女年龄不能大于55
	 * @param request
	 * @param response
	 * @param session
	 * @param limit
	 * @param id
	 * @param start
	 * @param end
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("/tqif")
	@ResponseBody
	public String tqif(HttpServletRequest request, HttpServletResponse response,HttpSession session, String limit ,String id,String start,String end) throws IOException{
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		Calendar c = Calendar.getInstance();//可以对每个时间域单独修改
		int year = c.get(Calendar.YEAR);
		Map reqMap = new HashMap();
		BODY b=new BODY();
		b.setGRZH(sessionIn.getGRZH());
		reqMap.put("AUTHORITY", "YBGJJ107");
		reqMap.put("OpenKey", sessionIn.getKEY());
		reqMap.put("BODY",b);
		OpenKey opk=new OpenKey();
		String result=opk.getOpenKey(reqMap, session);
		String zjhm=sessionIn.getZJHM().toString().substring(6, 10);
		int zjn=Integer.parseInt(zjhm);
		logger.info("接口返回内容:"+result);
		Map resMap = JSONUtil.toMap(result);
		int a=year-zjn;
		if(result != null){
			if(sessionIn.getXINGBIE().toString().equals("男")){	
				if(a>60){
					if(resMap.get("RETURNCODE").equals("100")){
						Map mx=JSONUtil.toMap(JSONUtil.ToJsongString2(resMap.get("body")));
						map.put("code", 0);
						map.put("msg", null);
						map.put("data", mx.get("RETDATA"));
						response.setHeader("Content-type", "text/html;charset=UTF-8");
						response.setCharacterEncoding("UTF-8");
						String jsonString = JSONUtil.ToJsongString2(map);
						PrintWriter pw = response.getWriter();
						pw.write(jsonString);
					}else{
						map.put("code", 1);
						map.put("CW", resMap.get("RETURNDESC").toString());
						response.setHeader("Content-type", "text/html;charset=UTF-8");
						response.setCharacterEncoding("UTF-8");
						String jsonString = JSONUtil.ToJsongString2(map);
						PrintWriter pw = response.getWriter();
						pw.write(jsonString);
					}
				}else{
					map.put("code", 1);
					map.put("CW", "您的年龄没有超过60岁不可以做退休提取");
					response.setHeader("Content-type", "text/html;charset=UTF-8");
					response.setCharacterEncoding("UTF-8");
					String jsonString = JSONUtil.ToJsongString2(map);
					PrintWriter pw = response.getWriter();
					pw.write(jsonString);
				}
			}else if(sessionIn.getXINGBIE().toString().equals("女")){
				if(a>55){
					if(resMap.get("RETURNCODE").equals("100")){
						Map mx=JSONUtil.toMap(JSONUtil.ToJsongString2(resMap.get("body")));
						map.put("code", 0);
						map.put("msg", null);
						map.put("data", mx.get("RETDATA"));
						response.setHeader("Content-type", "text/html;charset=UTF-8");
						response.setCharacterEncoding("UTF-8");
						String jsonString = JSONUtil.ToJsongString2(map);
						PrintWriter pw = response.getWriter();
						pw.write(jsonString);
					}else{
						map.put("code", 1);
						map.put("CW", resMap.get("RETURNDESC").toString());
						response.setHeader("Content-type", "text/html;charset=UTF-8");
						response.setCharacterEncoding("UTF-8");
						String jsonString = JSONUtil.ToJsongString2(map);
						PrintWriter pw = response.getWriter();
						pw.write(jsonString);
					}
				}else{
					map.put("code", 1);
					map.put("CW", "您的年龄没有超过55岁不可以做退休提取");
					response.setHeader("Content-type", "text/html;charset=UTF-8");
					response.setCharacterEncoding("UTF-8");
					String jsonString = JSONUtil.ToJsongString2(map);
					PrintWriter pw = response.getWriter();
					pw.write(jsonString);
				}
			}
			
		}
	
		return null;
	}
	@RequestMapping("/sj")
	@ResponseBody
	public String sj(HttpServletRequest request, HttpServletResponse response,HttpSession session, String limit ,String id,String start,String end) throws IOException, ParseException{
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		Map reqMap = new HashMap();
		DateUtil NIAN=new DateUtil();
		
		Date qsny=new Date();
		String qsrq=qsny+"";
		String zzqr=NIAN.minusM(qsny);
		System.out.println(qsrq+zzqr);
		reqMap.put("AUTHORITY", "YBGJJ106");
		reqMap.put("OpenKey", sessionIn.getKEY());
		BODY body=new BODY();
		body.setZJHM(sessionIn.getZJHM());
		reqMap.put("BODY", body);
		OpenKey opk=new OpenKey();
		String  result = opk.getOpenKey(reqMap, session);    
		logger.info("YBGJJ109接口返回内容:"+result);
		if(result != null){
			Map resMap = JSONUtil.toMap(result);
			if(resMap.get("RETURNCODE").equals("100")){
				//List resList = JSONUtil.toList(resMap.get("body").toString());
				Map mx=JSONUtil.toMap(JSONUtil.ToJsongString2(resMap.get("body")));
				//map.put("count", resList.size());
				map.put("code", 0);
				map.put("msg", "1");
				map.put("data", mx.get("RETDATA"));
				//list.add(resMap);
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
			}
		}
	
		return null;
	}
}

